<template>
	<view class="content columnbox wdh-100" v-if="message">
		<swiper class="swiper-box" indicator-dots>
			<swiper-item v-if="video!=''">
				<video class="wdh-100" style="height: 1000rpx;" :src='video'></video>
			</swiper-item>
			<swiper-item v-for="(item,index) in images" :key='index'>
				<image :src="item" mode="aspectFill"></image>
			</swiper-item>
		</swiper>
		<view class="info-title rowbox jus wdh-100">{{message.name}}</view>
		<rich-text :nodes="message.content" class="info-content wdh-100"></rich-text>
		<view class="wdh-100 rowbox jus time-box"> <text>{{message.addtime}}</text> <text>{{message.address}}</text>
		</view>
	</view>
</template>

<script>
	import getdate from '@/utils/time.js'
	export default {
		data() {
			return {
				id: 0,
				message: null,
				images: [],
				commentflag: false,
				commentvalue: '',
				pageNo: 1,
				commentList: [],
				submitflag: false, //是否上传中
				subcomflag: false, //查看子评论
				curcomment: null,
				subcominputflag: false, //子评论输入
				subcommentvalue: '',
				video: ''
			};
		},
		onLoad(options) {
			this.id = parseInt(options.id)
			this.getInfo()
			// this.getCommentList()
		},
		methods: {
			toChat() {
				uni.navigateTo({
					url: '/packageA/message/chat?id=' + this.message.uid
				})
			},
			showSbuComment(val) {
				this.curcomment = val
				this.subcomflag = true
				this.subcommentvalue = ''
				this.subcominputflag = false
			},
			// 发布子评论
			submitSubComment() {
				if (this.subcommentvalue == '') {
					uni.showToast({
						title: '请输入评论内容',
						icon: 'none'
					})
				} else {
					if (!this.submitflag) {
						this.submitflag = true
						uni.showLoading({
							title: '正在发布'
						})
						this.$req.post('/user/huifuadd', {
							uid: uni.getStorageSync('uid'),
							pinglunid: this.curcomment.id,
							content: this.subcommentvalue,
							city: uni.getStorageSync('cityinfo') ? uni.getStorageSync('cityinfo').id : ''
						}).then(res => {
							uni.hideLoading()
							this.submitflag = false
							this.subcommentvalue = ''
							this.subcominputflag = false
							uni.showToast({
								title: '评论成功',
								icon: 'success'
							})
							this.$req.post('/user/huifulist', {
								pinglunid: this.curcomment.id
							}).then(res => {
								res.data.data.forEach(resp => {
									resp.addtime = getdate.toMonthday(resp.addtime)
								})
								this.curcomment.List = res.data.data
								this.commentList.forEach(resp => {
									if (resp.id == this.curcomment.id) {
										resp.List = res.data.data
									}
								})
							})
						})
					}
				}
			},
			addSubComment() {
				this.subcominputflag = true
			},
			addCommentLike(val) {
				if (!this.submitflag) {
					this.submitflag = true
					if (val.ifzan != 2) {
						val.ifzan = 2
						val.zannum++
						this.$req.post('/user/pinglunzan', {
							uid: uni.getStorageSync('uid'),
							pinglunid: val.id
						}).then(res => {
							this.submitflag = false
						})
					} else {
						val.ifzan = 1
						val.zannum--
						this.$req.post('/user/pinglunzandel', {
							uid: uni.getStorageSync('uid'),
							pinglunid: val.id
						}).then(res => {
							this.submitflag = false
						})
					}
				}
			},
			cancelFollow() {
				this.message.guanzhu = 1
				this.$req.post('/user/followdel', {
					uid: uni.getStorageSync('uid'),
					userid: this.message.uid
				}).then(res => {

				})
			},
			addFollow() {
				this.message.guanzhu = 2
				this.$req.post('/user/followadd', {
					uid: uni.getStorageSync('uid'),
					userid: this.message.uid
				}).then(res => {

				})
			},
			getCommentList() {
				this.$req.post('/user/squarepllist', {
					id: this.id,
					pageNo: this.pageNo,
					pageSize: 20
				}).then(res => {
					res.data.data.forEach(resp => {
						if (resp.List) {
							resp.List.forEach(comment => {
								comment.addtime = getdate.toMonthday(comment.addtime)
							})
						}
						resp.addtime = getdate.toMonthday(resp.addtime)
					})
					this.commentList = res.data.data
				})
			},
			submitComment() {
				if (this.commentvalue.trim() == '') {
					uni.showToast({
						title: '请输入评论内容',
						icon: 'none'
					})
				} else {
					uni.showLoading({
						title: '正在发布...'
					})
					this.$req.post('/user/squarepladd', {
						id: this.id,
						uid: uni.getStorageSync('uid'),
						city: uni.getStorageSync('cityinfo') ? uni.getStorageSync('cityinfo').id : '',
						content: this.commentvalue
					}).then(res => {
						uni.showToast({
							title: '评论已发布'
						})
						uni.hideLoading()
						this.commentvalue = ''
						this.commentflag = false
						this.pageNo = 1
						this.commentList = []
						this.getCommentList()
						this.getInfo()
					})
				}
			},
			addComment() {
				this.commentflag = true
				this.commentvalue = ''
			},
			addLike() {
				if (this.message.iflike != 2) {
					this.message.iflike = 2
					this.$req.post('/user/squarezan', {
						id: this.id,
						uid: uni.getStorageSync('uid')
					}).then(res => {
						this.message.dznum++
					})
				} else {
					this.message.iflike = 0
					this.$req.post('/user/squarezandel', {
						id: this.id,
						uid: uni.getStorageSync('uid')
					}).then(res => {
						this.message.dznum--
					})
				}
			},
			addKeep() {
				if (this.message.ifcollect != 2) {
					this.message.ifcollect = 2
					this.$req.post('/user/squaresc', {
						id: this.id,
						uid: uni.getStorageSync('uid')
					}).then(res => {
						this.message.scnum++
					})
				} else {
					this.message.ifcollect = 0
					this.$req.post('/user/squarescdel', {
						id: this.id,
						uid: uni.getStorageSync('uid')
					}).then(res => {
						this.message.scnum--
					})
				}
			},
			getInfo() {
				this.$req.post('/admin/newsinfo', {
					id: this.id
				}).then(res => {
					console.log(res)
					res.data.data.addtime = getdate.couponDate(res.data.data.addtime)
					this.message = res.data.data
					this.images = res.data.data.images == '' ? [] : res.data.data.images.split(',')
					this.video = res.data.data.video
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {}

	.top-box {
		padding: 28rpx 40rpx;
	}

	.user-img {
		width: 60rpx;
		height: 60rpx;
		border-radius: 100rpx;
		margin-right: 10rpx;
	}

	.user-name {
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #333333;
	}

	.user-iden {
		font-size: 16rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #ADADAD;
	}

	.follow-btn {
		width: 100rpx;
		height: 48rpx;
		background: linear-gradient(139deg, #1BF79D 0%, #3DEEF9 100%);
		border-radius: 30rpx;
		font-size: 24rpx;
		font-family: Alibaba PuHuiTi, Alibaba PuHuiTi;
		font-weight: bold;
		color: #000000;
		margin-right: 30rpx;
	}

	.share-btn {
		width: 48rpx;
		height: 48rpx;
	}

	.swiper-box {
		width: 750rpx;
		height: 1000rpx;

		image {
			width: 750rpx;
			height: 1000rpx;
		}
	}

	.info-title {
		margin-top: 40rpx;
		padding: 0 30rpx;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 600;
		color: #333333;
		line-height: 40rpx;
	}

	.info-content {
		margin-top: 20rpx;
		padding: 0 30rpx;
		box-sizing: border-box;
		font-size: 32rpx;
		font-family: PingFang SC, PingFang SC;
		color: #333333;
		line-height: 48rpx;
	}

	.bottom-box {
		padding-bottom: 40px;
		background: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 9;
		padding-top: 20rpx;
		box-sizing: content-box;
	}

	.comment-box {
		margin-left: 30rpx;
		width: 240rpx;
		height: 80rpx;
		background: #F3F3F3;
		border-radius: 42rpx;
		font-size: 28rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #969696;
		line-height: 40rpx;
		padding: 0 20rpx;

		image {
			margin-right: 6rpx;
			width: 30rpx;
			height: 30rpx;
		}
	}

	.status-box {
		margin-right: 30rpx;

		.one-status {
			font-size: 22rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #000000;
			margin-left: 30rpx;

			image {
				width: 60rpx;
				height: 60rpx;
				margin-right: 10rpx;
			}
		}
	}

	.time-box {
		width: 690rpx;
		padding: 30rpx 0;
		// border-bottom: #E1E1E1 solid 1px;
		font-size: 22rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #C3C3C3;

		text {
			margin-right: 20rpx;
		}
	}

	.nocomment-box {
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		color: #B1B1B1;

		.no-comment-img {
			width: 80rpx;
			height: 54rpx;
			margin-bottom: 20rpx;
		}
	}

	.comment-title {
		margin-top: 28rpx;
		margin-bottom: 20rpx;
		padding: 0 30rpx;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #000000;
	}

	.comment-input-box {
		padding: 20rpx 30rpx;

		.comment-textarea-box {
			width: 600rpx;
			background: #F3F3F3;
			padding: 20rpx 20rpx;
			border-radius: 30rpx;
		}

		.comment-textarea {
			width: 100%;
			background: #F3F3F3;
			font-size: 28rpx;
		}

		.send-btn {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 600;
			color: #FF3F4A;
			line-height: 40rpx;
		}
	}

	.one-comment {
		padding: 20rpx 30rpx;

		.comment-user-img {
			width: 60rpx;
			height: 60rpx;
			border-radius: 100rpx;
			margin-right: 20rpx;
		}
	}

	.comment-info {
		width: calc(100% - 140rpx);

		.comment-user-name {
			font-size: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #333333;
			line-height: 40rpx;
		}

		.comment-detail {
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			color: #333333;
			line-height: 40rpx;
			margin-top: 20rpx;
			margin-bottom: 10rpx;
		}

		.comment-manage {
			margin-top: 10rpx;

			.replay-box {
				padding: 0 14rpx;
				font-size: 20rpx;
				line-height: 40rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				color: #333333;
				background: #F3F3F3;
				border-radius: 40rpx;
				margin-right: 20rpx;
			}
		}

		.comment-time {
			font-size: 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #C3C3C3;

			text {
				margin-right: 20rpx;
			}
		}
	}

	.comment-like {
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #C3C3C3;

		image {
			width: 30rpx;
			height: 30rpx;
		}
	}

	.comment-like-num {
		font-size: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #000000;
		margin-top: 60rpx;
	}

	.sub-comment-box {
		padding-bottom: 40px;
		position: fixed;
		bottom: 0;
		left: 0;
		background: #fff;

		.sub-comment-input-box {
			margin-left: 30rpx;
			width: 500rpx;
			height: 80rpx;
			background: #F3F3F3;
			border-radius: 42rpx;
			font-size: 28rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #969696;
			line-height: 40rpx;

			image {
				width: 30rpx;
				height: 30rpx;
				margin-left: 20rpx;
				margin-right: 10rpx;
			}
		}

		.sub-zan {
			font-size: 22rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #000000;
			margin-right: 30rpx;

			image {
				width: 60rpx;
				height: 60rpx;
				margin-right: 10rpx;
			}
		}
	}

	.sub-comment-list {
		padding: 0 30rpx;
	}

	.sub-comment-title {
		margin-top: 28rpx;
		font-size: 24rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		color: #000000;
		margin-bottom: 20rpx;
	}

	.video-box {
		width: 100%;
		height: calc(100vh - 20px - 70rpx);
	}

	.video-bottom-box {
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 20;
		color: #fff;
		padding: 0 0;

		.video-user-img {
			width: 60rpx;
			height: 60rpx;
			border-radius: 100rpx;
			margin-right: 10rpx;
		}

		.video-user-name {
			font-size: 24rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 400;
			color: #D9D9D9;
		}

		.video-title {
			margin-top: 20rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 600;
			color: #FFFFFF;
			line-height: 40rpx;
		}

		.video-content {
			margin-top: 20rpx;
			font-size: 32rpx;
			font-family: PingFang SC, PingFang SC;
			color: #FFFFFF;
			line-height: 48rpx;
		}

		.video-manage-box {
			background: #000;
			color: #fff;
			margin-top: 20rpx;
			padding: 0 40rpx;
			padding-bottom: 20px;

			.comment-box {
				margin-left: 0;
				background: #333333;
				color: #fff;
			}

			.one-status {
				color: #fff;
			}
		}
	}
</style>